//
//  TabbarController.m
//  CoachsBook
//
//  Created by MaBookPro on 2022/8/8.
//

#import "TabbarController.h"

@interface TabbarController ()

@end

@implementation TabbarController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tabBar.hidden = YES;
    [self XTCreatTabbarListUI];
    // Do any additional setup after loading the view.
}


-(void)XTCreatTabbarListUI{
    NSArray *fourbtnarr = [NSArray arrayWithObjects:@"首页",@"线索",@"管理",@"我的", nil];
    NSArray *fourbtnimagearr = [NSArray arrayWithObjects:@"shouye",@"xiansuo",@"guanli",@"wode", nil];
    NSArray *fourbtnimagearr1 = [NSArray arrayWithObjects:@"home_fill_light",@"list_fill_light",@"plus_fill_light",@"my_fill_light", nil];
    
    
    _tabBarView = [[UIView alloc] initWithFrame:CGRectMake(0, APPheight - 49-SafeAreaBottomHeight, APPwidth, 49 + SafeAreaBottomHeight)];
    _tabBarView.backgroundColor =  [UIColor whiteColor];
    [self.view addSubview:_tabBarView];
    _tabBarView.layer.shadowColor = [UIColor grayColor].CGColor;//阴影颜色
    _tabBarView.layer.shadowOffset = CGSizeMake(0, 0);//偏移距离
    _tabBarView.layer.shadowOpacity = 0.2;//不透明度
    _tabBarView.layer.shadowRadius = 2.0;//半径

    
    float w = self.view.frame.size.width/4;
    for (int i = 0; i < fourbtnarr.count; i++)
    {
        
        //四个按钮
        UIButton * btn = [[UIButton alloc] initWithFrame:CGRectMake(i * w, 0, w, _tabBarView.frame.size.height-SafeAreaBottomHeight)];
        btn.tag = 1000+i;
        [btn setImage:[UIImage imageNamed:fourbtnimagearr[i]] forState:0];
        [btn setImage:[UIImage imageNamed:fourbtnimagearr1[i]] forState:1<<2];
        btn.imageEdgeInsets = UIEdgeInsetsMake(0, 0, 20, 0);
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [_tabBarView addSubview:btn];
        
        
//        UIImageView *imgv =[[UIImageView alloc]initWithFrame:CGRectMake(btn.frame.size.width/2-10 , btn.frame.size.height/2-19.5, 20, 20)];
//        imgv.image = [UIImage imageNamed: logoimg[i]];
//        [btn addSubview:imgv];
        //四个按钮标题
        UILabel * label = [[UILabel alloc] initWithFrame:CGRectMake(0, btn.frame.size.height-20, btn.frame.size.width, 15)];
        label.text = fourbtnarr[i];
        label.tag = 2000+i;
        label.font = [UIFont systemFontOfSize:12];
        label.textAlignment = NSTextAlignmentCenter;
        label.textColor = rgba(204, 204, 204, 1);
        [btn addSubview:label];
                
        if (i == 0) {
            
            btn.selected = YES;
            label.textColor = rgba(245, 63, 64, 1);
        }
    }
}
#pragma mark - tabbar上按钮点击-进入相应的模块
-(void)btnClick:(UIButton *)btn
{
    
    self.selectedIndex = btn.tag - 1000;
    
    for(int i = 0; i < 4 ;i++)
    {
        UIButton * btn1 = (UIButton *)[self.view viewWithTag:1000+i];
        btn1.selected = NO;
        
        UILabel * label = (UILabel *)[self.view viewWithTag:2000+i];
        label.textColor = rgba(204, 204, 204, 1);
        
        if (label.tag-1000 == btn.tag) {
            
            label.textColor = rgba(245, 63, 64, 1);
            
        }
        
    }
    
    btn.selected = YES;
    
    
    
    
    
}

@end
